package tag.in.activities;

import tag.in.Constants;
import tag.in.R;
import tag.in.TagInApplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

/**
 * Just to show the logo.
 * 
 * @author andre
 */
public class TagLogoActivity extends Activity {

    private static final String CLASSTAG = TagLogoActivity.class.getSimpleName();
    private static final int MENU_NEXT = Menu.FIRST;
    private ImageView logo;    
    private Handler mHandler = new Handler();
    
    /*
     * Timer Callback.
     * Just call handleNext()
     * 
     */
    private Runnable mUpdateTimeTask = new Runnable() {
    	   public void run() {
    	       handleNext();
    	       mHandler.removeCallbacks(mUpdateTimeTask);
    	   }
    	};
    	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v(Constants.LOGTAG, " " + TagLogoActivity.CLASSTAG + " onCreate");

        this.setContentView(R.layout.tag_logo);

        this.logo = (ImageView) findViewById(R.id.tag_logo);
        
        /*
         * Set timer, 3s
         * 
         */
        mHandler.removeCallbacks(mUpdateTimeTask);
        mHandler.postDelayed(mUpdateTimeTask, 3000);
        
        this.logo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //handleNext();
            }
        });
    }   

    @Override
    protected void onResume() {
        super.onResume();
        Log.v(Constants.LOGTAG, " " + TagLogoActivity.CLASSTAG + " onResume");
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        /*menu.add(0, TagLogoActivity.MENU_NEXT, 0, R.string.logo_text).setIcon(
            android.R.drawable.ic_menu_more);*/
        return true;
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch (item.getItemId()) {
            case MENU_NEXT:
                //handleNext();
                //return true;
        }
        return super.onMenuItemSelected(featureId, item);
    }
    
    private void handleNext() {
    	// use the "Application" to store global state (can go beyond primitives and Strings -
        // beyond extras - if needed)
    	// Use current location and default category to filter results
        TagInApplication application = (TagInApplication) getApplication();
        application.setTagAction("list");
        application.setTagType("all");
        
        String[] categories = getResources().getStringArray(R.array.categories);
        application.setTagCategories(categories);

        // call next Activity, VIEW_LIST
        Intent intent = new Intent(Constants.INTENT_ACTION_VIEW_LOGIN);
        startActivity(intent);
    }
}
